<?php
/**
 * XmuSlh, web platform of Student Association Federation of Xiamen University
 * 
 * Rewritting one or some pages of StatusNet. 
 * To get the original version, please visit <http://status.net/>.
 * 
 * StatusNet, the distributed open-source microblogging tool
 * 
 * LICENCE: This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * Edit (or delete) a user account. Especially the rights.
 * DataList!
 * 
 * @author		ytukie <ytukie@gmail.com>
 * @version		0.3
 * 
 * 0.2)  Inherited from ListAction.
 * 0.3)  Adds a 'SearchBox' widget.
 */

// XmuSlh only.
if ( !defined('XMUSLH')) { exit(1); }

// Requirements.
require_once INSTALLDIR . '/lib/slh_listaction.php';
require_once INSTALLDIR . '/widgets/slh_list_data.php';
require_once INSTALLDIR . '/lib/slh_searchbox.php';

require_once INSTALLDIR . '/classes/Data.php';


class DataAction extends ListAction
{
	/**
	 * The datas in the list.
	 */
	var $data = null;
	
	/**
	 * Constructor.
	 * To pass some variables to the parent. 
	 */
	function __construct()
	{
		parent::__construct('data',
							DATAS_PER_PAGE);
	}
	
	function title()
	{
		return '资料下载';
	}
	
	function prepare($args)
	{
		parent::prepare($args);
		
// TODO: To distinguish the all/slh/association?
		$status = 0;
		
		// Get the datas.
		$ids = Data::getIdsByList(($this->page - 1) * DATAS_PER_PAGE,
                              	   DATAS_PER_PAGE + 1);

		// Check if has next page, and remove the last id which is extra.
		$this->doPagination($ids);
        
        $this->data = Data::getDatasByIds($ids);
        
        // Check the page validation.
        $this->checkPagination($this->data->N);
        
		return true;
	}
	
	/**
	 * Add the autocomplete stylesheet.
	 */
	function showStylesheets()
	{
		parent::showStylesheets();
		
		$this->cssLink('theme/base/css/jquery.autocomplete.css', 'base', 'screen, projection, tv');
	}
	
	/**
	 * Add the autocomplete scripts.
	 */
	function showScripts()
	{
		parent::showScripts();

		$this->script('autocomplete/jquery.autocomplete.min.js');
		$this->script('widget/searchbox.go.js');
	}
	
	/**
	 * Overrided.
	 */
	function showAddition()
	{
		// Show the search box.
		$searchbox = new SearchBox(array('s' => 'datasearchjson',
										 'r' => 'datasearchresulthtml',
										 'g' => 'getdata'), $this);
		$searchbox->show();
	}
	
	/**
	 * Overrided.
	 */
	function showList()
	{
		$list = new DataList($this->data, $this);
		$list->show();
	}
	
}
?>